package lanou.autohome.find.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import lanou.autohome.R;
import lanou.autohome.basetool.NetTool;
import lanou.autohome.find.FindBean;

/**
 * Created by dllo on 16/8/23.
 */
public class FindAdapterTable extends RecyclerView.Adapter<FindAdapterTable.MyViewHolder>{

    private Context mcontext;
    private FindBean findBean;

    public FindAdapterTable(Context mcontext) {
        this.mcontext = mcontext;
    }

    public void setFindBean(FindBean findBean) {
        this.findBean = findBean;
        notifyDataSetChanged();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mcontext).inflate(R.layout.item_find_recyclerview_table , null);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {

        FindBean.ResultBean.GoodslistBean.ListBean listBean = findBean.getResult().getGoodslist().getList().get(position);

        holder.title.setText(listBean.getTitle());
        holder.shorttitle.setText(listBean.getShorttitle());
        holder.price.setText(String.valueOf(listBean.getPrice()));
        holder.fctprice.setText(String.valueOf(listBean.getFctprice()));

        NetTool netTool = new NetTool();
        netTool.getImage(findBean.getResult().getGoodslist().getList().get(position).getLogo() , holder.logo);

    }

    @Override
    public int getItemCount() {
        return findBean != null ? findBean.getResult().getGoodslist().getList().size() :0;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView title;
        TextView shorttitle;
        TextView price;
        TextView fctprice;
        ImageView logo;
        public MyViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.title_table_find_recyclerview);
            shorttitle = (TextView) itemView.findViewById(R.id.shorttitle_table_find_recyclerview);
            price = (TextView) itemView.findViewById(R.id.price_table_find_item);
            fctprice = (TextView) itemView.findViewById(R.id.fctprice_table_find_recyclerview);
            logo = (ImageView) itemView.findViewById(R.id.logo_table_find_recyclerview);
        }
    }
}